﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

/// <summary>
/// staff 的摘要说明
/// </summary>
public class staff : SQLHelper
{
    //定义kh类的数据成员（属性）
    private string snum;
    private string sname;
    private string saddress;
    private string spw;
    private string sphone;
    private string sidcard;
    private string sbirth;
    private string sprovince;
    private string scity;
    private string sqq;
    private string smail;
    private string sproblem;
    private string sanswer;

    public string num
    {
        get { return snum; }
        set { snum = value; }
    }
    public string name
    {
        get { return sname; }
        set { sname = value; }
    }
    public string address
    {
        get { return saddress; }
        set { saddress = value; }
    }
    public string pw
    {
        get { return spw; }
        set { spw = value; }
    }
    public string phone
    {
        get { return sphone; }
        set { sphone = value; }
    }
    public string idcard
    {
        get { return sidcard; }
        set { sidcard = value; }
    }
    public string birth
    {
        get { return sbirth; }
        set { sbirth = value; }
    }
    public string province
    {
        get { return sprovince; }
        set { sprovince = value; }
    }
    public string city
    {
        get { return scity; }
        set { scity = value; }
    }
    public string qq
    {
        get { return sqq; }
        set { sqq = value; }
    }
    public string mail
    {
        get { return smail; }
        set { smail = value; }
    }
    public string problem
    {
        get { return sproblem; }
        set { sproblem = value; }
    }
    public string answer
    {
        get { return sanswer; }
        set { sanswer = value; }
    }
	public staff()
	{
		//
		// TODO: 在此处添加构造函数逻辑
		//
	}
    //查找账号num是否存在
    public int IsidExist(staff tmp)
    {
        string sql = "select count(*)from staff where Snum='" + tmp.num + "'";
        int result = tmp.ExeScalar(sql);
        return result;
    }
    //添加一个客户的信息
    public int Addonestaff(staff tmp)
    {
        string sql = "insert into staff(Snum,Spw,Sidcard,Sname,Sphone,Saddress) values('" + tmp.num +
            "','" + tmp.pw +
            "','" + tmp.idcard +
            "','" + tmp.name +
            "','" + tmp.phone +
            "','" + tmp.address + "')";
        int result = tmp.ExeNonQuery(sql);
        return result;
    }
    //删除
    public int Deleteonestaff(staff tmp)
    {
        string sql = "delete from staff where Snum='" + tmp.num + "'";
        int result = tmp.ExeNonQuery(sql);
        return result;
    }
    //更新一个学生信息
    public int Updateonestaff(staff tmp)
    {
        string sql = "update staff set Sname='" + tmp.name +
                "', Spw= '" + tmp.pw +
                "', Sidcard= '" + tmp.idcard +
                "', Sprovince= '" + tmp.province +
                "', Scity= '" + tmp.city +
                "', Sbirth= '" + tmp.birth +
                "', Sqq= '" + tmp.qq +
                "' ,Smail= '" + tmp.mail +
                "' ,Sphone= '" + tmp.phone +
                "', Saddress= '" + tmp.address +
                "', Sproblem= '" + tmp.problem +
                "', Sanswer= '" + tmp.answer +
                "' where Snum= '" + tmp.num + "'";
        int result = tmp.ExeNonQuery(sql);
        return result;
    }
    //删除学生信息

    public int Login(staff tmp)
    {
        string sql = "select count(*) from staff where Snum='" + tmp.num + "' and Spw='" + tmp.pw + "'";
        int result = tmp.ExeScalar(sql);
        return result;
    }
    //读取一个学生的信息
    public SqlDataReader Getonestaff(staff tmp)
    {
        string sql = "select * from staff where Snum='" + tmp.num + "'";
        SqlDataReader rd = tmp.ExeReader(sql);
        return rd;
    }
    //绑定省份
    public DataSet BindProvince()
    {
        staff tmp = new staff();
        string sql = "select * from T_province";
        DataSet ds = tmp.GetDs(sql);
        return ds;
    }

    //绑定市区
    public DataSet BindCity(string proid)
    {
        staff tmp = new staff();
        string sql = "select * from T_city where proID='" + proid + "'";
        DataSet ds = tmp.GetDs(sql);
        return ds;
    }
    //获取所有学生的信息
    public DataSet GetAllStaff()
    {
        staff tmp = new staff();
        string sql = "select * from staff";
        //,T_province,T_city where"
        //+
        //"t_users.u_PROVINCE=T_province.FID and T_province.FID=T_city.proID and "
        // +"t_users.u_city=T_city.FcityID";
        DataSet ds = tmp.GetDs(sql);
        return ds;
    }
    public DataSet GetOneStaff(staff tmp)
    {
        string sql = "select * from staff where Snum='" + tmp.num + "'";
        DataSet ds = tmp.GetDs(sql);
        return ds;
    }
}